package nl.aronmandos.myhealth.dal;

import nl.aronmandos.myhealth.domain.Example;
import nl.aronmandos.myhealth.repositories.ExampleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.test.context.ContextConfiguration;

import java.util.List;

/**
 * An example Data acces layer class
 *
 * Created by Aron on 17-9-2014.
 */
@ContextConfiguration(locations= "classpath:META-INF/applicationContext.xml")
@Service
public class ExampleDAL implements IExampleDAL{
    //this simulates DB now.

    @Autowired
    ExampleRepository repository;
    /**
     * gets all Examples
     * @return a list of Examples
     */
    public List<Example> getExamples(){
        try {
            return repository.findAll();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * gets a Example by its id
     * @param id the id of a Example
     * @return a Example
     */
    public Example getExample(int id){
        System.out.println("[ExampleDAL]getExample id: "+1);
        try {
            return repository.findOne(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
